package cn.zcscloud.mall.controller;

import cn.zcscloud.mall.common.PageRequest;
import cn.zcscloud.mall.common.R;
import cn.zcscloud.mall.mbg.model.SmsCouponHistory;
import cn.zcscloud.mall.service.SmsCouponHistoryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/couponHistory")
public class SmsCouponHistoryController {
    @Autowired
    private SmsCouponHistoryService smsCouponHistoryService;

    @GetMapping("/list")
    public R list(@RequestParam(value = "couponId", required = false) Long couponId,
                  @RequestParam(value = "useStatus", required = false) Integer useStatus,
                  @RequestParam(value = "orderSn", required = false) String orderSn,
                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        LambdaQueryWrapper<SmsCouponHistory> lqw = new LambdaQueryWrapper<>();
        lqw.eq(couponId != null,SmsCouponHistory::getCouponId, couponId);
        lqw.eq(useStatus != null,SmsCouponHistory::getUseStatus,useStatus);
        lqw.like(orderSn != null,SmsCouponHistory::getOrderSn,orderSn);
        Page<SmsCouponHistory> page = new Page<>(pageNum, pageSize);
        Page<SmsCouponHistory> iPage = smsCouponHistoryService.page(page, lqw);
        return R.success(PageRequest.init(iPage));

    }
}
